<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="测试点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="testPoints">
              <a-input v-model="model.testPoints" placeholder="请输入测试点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标准值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standard">
              <a-input v-model="model.standard" placeholder="请输入标准值"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lowerLimit">
              <a-input v-model="model.lowerLimit" placeholder="请输入下限"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="upLimit">
              <a-input v-model="model.upLimit" placeholder="请输入上限"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection1">
              <j-date placeholder="请选择检测时间1"  v-model="model.detection1" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality1">
              <a-input v-model="model.reality1" placeholder="请输入实际1"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate1">
              <a-input v-model="model.deviate1" placeholder="请输入偏离1"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection2">
              <j-date placeholder="请选择检测时间2"  v-model="model.detection2" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality2">
              <a-input v-model="model.reality2" placeholder="请输入实际2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate2">
              <a-input v-model="model.deviate2" placeholder="请输入偏离2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection3">
              <j-date placeholder="请选择检测时间3"  v-model="model.detection3" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality3">
              <a-input v-model="model.reality3" placeholder="请输入实际3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate3">
              <a-input v-model="model.deviate3" placeholder="请输入偏离3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间4" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection4">
              <j-date placeholder="请选择检测时间4"  v-model="model.detection4" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际4" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality4">
              <a-input v-model="model.reality4" placeholder="请输入实际4"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离4" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate4">
              <a-input v-model="model.deviate4" placeholder="请输入偏离4"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间5" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection5">
              <j-date placeholder="请选择检测时间5"  v-model="model.detection5" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际5" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality5">
              <a-input v-model="model.reality5" placeholder="请输入实际5"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离5" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate5">
              <a-input v-model="model.deviate5" placeholder="请输入偏离5"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间6" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection6">
              <j-date placeholder="请选择检测时间6"  v-model="model.detection6" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际6" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality6">
              <a-input v-model="model.reality6" placeholder="请输入实际6"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离6" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate6">
              <a-input v-model="model.deviate6" placeholder="请输入偏离6"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间7" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection7">
              <j-date placeholder="请选择检测时间7"  v-model="model.detection7" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际7" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality7">
              <a-input v-model="model.reality7" placeholder="请输入实际7"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离7" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate7">
              <a-input v-model="model.deviate7" placeholder="请输入偏离7"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间8" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection8">
              <j-date placeholder="请选择检测时间8"  v-model="model.detection8" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际8" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality8">
              <a-input v-model="model.reality8" placeholder="请输入实际8"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离8" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate8">
              <a-input v-model="model.deviate8" placeholder="请输入偏离8"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间9" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection9">
              <j-date placeholder="请选择检测时间9"  v-model="model.detection9" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际9" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality9">
              <a-input v-model="model.reality9" placeholder="请输入实际9"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离9" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate9">
              <a-input v-model="model.deviate9" placeholder="请输入偏离9"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="检测时间10" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detection10">
              <j-date placeholder="请选择检测时间10"  v-model="model.detection10" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实际10" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reality10">
              <a-input v-model="model.reality10" placeholder="请输入实际10"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="偏离10" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviate10">
              <a-input v-model="model.deviate10" placeholder="请输入偏离10"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ReportFourForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/reportFour/add",
          edit: "/ch/reportFour/edit",
          queryById: "/ch/reportFour/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>